<?php
declare (strict_types=1);

namespace app\index\controller;

use app\common\model\RafflePrize;
use app\common\model\RaffleRecord;
use app\common\tool\Result;
use think\facade\View;
use think\Response;

class Raffle extends Base
{
    public function index(): string
    {
        $prize = RafflePrize::getPrize();
        View::assign('prize', $prize);

        return View::fetch();
    }

    public function submit(): Response
    {
        return Result::fastReturn(RaffleRecord::submit($this->user, $this->system));
    }

    public function record(): string|Response
    {
        if ($this->request->isAjax()) {
            $map = ['uid' => $this->user->id];

            return Result::fastReturn(RaffleRecord::getPageList($map, 'id,uid,title,icon,amount,create_time',
                $this->getPage(), $this->getLimit(), false));
        }

        return View::fetch();
    }
}